import axios from 'axios'

const BASE_URL = import.meta.env.VITE_APP_BASE_API

/**
 * 大棚相关API
 */
export const greenhouseApi = {
  /**
   * 获取所有大棚列表
   */
  getAllGreenhouses() {
    return axios.get(`${BASE_URL}/greenhouses`)
  },

  /**
   * 获取大棚详细信息
   */
  getGreenhouseDetail(id) {
    return axios.get(`${BASE_URL}/greenhouses/${id}`)
  },

  /**
   * 获取传感器数据
   */
  getSensorData(deviceId) {
    return axios.get(`${BASE_URL}/devices/${deviceId}/sensor-data`)
  },

  /**
   * 获取设备历史数据
   */
  getDeviceHistory(deviceId, timeRange, limit) {
    return axios.get(`${BASE_URL}/devices/${deviceId}/history`, {
      params: {
        timeRange,
        limit
      }
    })
  },

  /**
   * 获取摄像头视频流
   */
  getVideoStream(deviceId) {
    return axios.get(`${BASE_URL}/devices/${deviceId}/video-stream`)
  },

  /**
   * 获取摄像头历史记录
   */
  getCameraRecords(deviceId) {
    return axios.get(`${BASE_URL}/devices/${deviceId}/camera-records`)
  },

  /**
   * 获取摄像头设备列表
   */
  getCameraDevices(greenhouseId) {
    return axios.get(`${BASE_URL}/devices/cameras`, {
      params: {
        greenhouseId,
        deviceTypeId: 2 // 假设2是摄像头设备类型的ID
      }
    })
  },

  /**
   * 获取图表数据
   */
  getChartData(deviceId, limit = 6) {
    return axios.get(`${BASE_URL}/devices/${deviceId}/chart-data`, {
      params: { limit }
    })
  }
}
